<template>
  <div>
    <div class="nav-bar nav-hairline--bottom">
      <div class="nav-bar_content" :style="opacityStyle">
        <div class="nav-bar_left">
          <span class="nav-bar_text" :class="{'isActiveColor': isClassName}">{{title}}</span>
        </div>
        <div class="nav-bar_right">
          <span class="icon-star-wrap" :class="{'isActiveStyle': isClassName}">
            <i class="iconfont">&#xe625;</i>
          </span>
          <span class="iconWrap" :class="{'isActiveStyle': isClassName}">
            <i class="iconfont">&#xe601;</i>
            <i class="iconfont line">&#xe63a;</i>
            <i class="iconfont">&#xe600;</i>
          </span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'Header',
  props: {
    title: {
      type: String,
      default: "江苏政务服务"
    }
  },
  data () {
    return {
      isClassName: false,
      opacityStyle: {
        opacity: 1
      },
    }
  },
  mounted () {
    window.addEventListener('scroll', this.handleScroll)
  },
  destroyed () {
    window.removeEventListener('scroll', this.handleScroll)
  },
  methods: {
    handleScroll () {
      const top = document.documentElement.scrollTop || document.body.scrollTop || window.pageYOffset
      if (top > 46) {
        let opacity = top / 140;
        opacity = opacity > 1 ? 1 : opacity;
        this.isClassName = opacity > 0.5 ? true : false;
        this.opacityStyle = { 
          opacity,
          backgroundColor: '#fff'
        };
      } else {
        this.opacityStyle = { 
          opacity: 1,
          backgroundColor: 'transparent'
        };
        this.isClassName = false;
      }
    }
  },
}
</script>

<style lang="less" scoped>
  @import '~styles/varibles.less';
  .nav-bar  {
    position: relative;
    z-index: 99;
    height: @headerHeight;
    user-select: none;
    &_content {
      position: fixed;
      width: 100%;
      height: @headerHeight;
      display: flex;
      align-items: center;
      color: #fff;
    }
    .header-abs-back {
      font-size: @navIconFontSize;
      margin-right: 10px;
    }
    &_left {
      left: 0;
    }
    &_right {
      right: 0;
    }
    &_left, &_right {
      position: absolute;
      top: 0;
      bottom: 0;
      display: flex;
      align-items: center;
      padding: 0 14px;
      font-size: @navFontSize;
      cursor: pointer;
    }
    .isActiveColor {
      color: #000;
    }
    .icon-star-wrap {
      padding: 4px;
      border-radius: 50%;
      background-color: rgba(0,0,0,0.3);
      margin-right: 10px;
      .iconfont {
        font-size: @navIconFontSize;
      }
    }
    .iconWrap {
      display: flex;
      align-items: center;
      padding: 4px 10px;
      border-radius: 20px;
      background-color: rgba(0,0,0,0.3);
      .iconfont {
        font-size: @navIconFontSize;
      }
      .line {
        vertical-align: middle;
        color:#eaeaea;
        font-size: 16px;
      }
    }
    .isActiveStyle {
      background-color: #fff;
      border: 0.5px solid #efefef;
      .iconfont {
        color:#000;
        font-weight: 600;
      }
    }
  }
  .nav-hairline--bottom::after {
    border-bottom-width: 1px;
    position: absolute;
    box-sizing: border-box;
    content: ' ';
    pointer-events: none;
    top: -50%;
    right: -50%;
    bottom: -50%;
    left: -50%;
    border: 0 solid #ebedf0;
    transform: scale(0.5);
  }
</style>
